package com.hfzy.ihk.facade.linkcall.enums;

import com.hfzy.ihk.common.facade.elasticsearch.ElasticsearchVersionRedisKey;
import com.hfzy.ihk.common.facade.elasticsearch.entity.ElasticsearchTable;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018/7/19.
 *
 * 基于redis的版本控制
 *
 *  redis key
 * @author wws
 */
public enum LinkCallRedisVersionKey implements ElasticsearchVersionRedisKey {

    TABLE_TEST_LOG("version","xxxx",LinkCallTables.TEST_LOG),
    TABLE_TEST_LOG_NAME("nameFieldVersion","xxxx",LinkCallTables.TEST_LOG),
    TABLE_TEST_Entity("version","xxxx",LinkCallTables.TEST_ENTITY),
    TABLE_CALL_TASK("calltask","call客任务包",LinkCallTables.CALL_TASK),
    TABLE_CALL_TASK_PHONE("calltask","呼叫任务的号码",LinkCallTables.CALL_TASK_PHONE),
    TABLE_SPEAKING_PACKAGE("speakingpackage","",LinkCallTables.SPEAKING_PACKAGE),
    TABLE_SPEAKING_FLOW("speakingflow","",LinkCallTables.SPEAKING_FLOW),
    TABLE_SPEAKING_FLOW_STEP("speakingflowstep","",LinkCallTables.SPEAKING_FLOW_STEP)
    ;

    private LinkCallRedisVersionKey(String value, String desc, ElasticsearchTable belongTable){
        this.value = value;
        this.desc = desc;
        this.belongTable = belongTable;
    }

    private String value;

    private String desc;

    private ElasticsearchTable belongTable;

    public String getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    @Override
    public String getVersionKeyName() {
        return belongTable.getTableName()+":"+value;
    }

    private static Map<String, LinkCallRedisVersionKey> map = new HashMap<String, LinkCallRedisVersionKey>();
    static {
        for (LinkCallRedisVersionKey value : LinkCallRedisVersionKey.values()) {
            map.put(value.getValue(), value);
        }
    }

    public static LinkCallRedisVersionKey fromValue(String value) {
        LinkCallRedisVersionKey ret = map.get(value);
        if (ret != null) {
            return ret;
        } else {
            throw new IllegalArgumentException("No enum const " + LinkCallRedisVersionKey.class + "." + value);
        }
    }
}
